package cz.cvut.fit.mi_paa.sat;

import java.util.ArrayList;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: milos
 * Date: 27.1.13
 * Time: 21:45
 * To change this template use File | Settings | File Templates.
 */
public class Term {
    private List<Integer> variables;

    public Term() {
        variables = new ArrayList<Integer>();
    }

    public void addVariable(int var) {
        variables.add(var);
    }

    public boolean isSatisfiable(boolean [] array) {
        boolean result=false;
        for (Integer variable : variables) {
            result |= ((variable<0) ^ array[Math.abs(variable)-1]);
        }
        return result;
    }

    public int getTermWeight(int[] weights) {
        int weight=0;
        for (Integer variable : variables) {
            weight += weights[Math.abs(variable)-1];
        }
        return weight;

    }
}
